"""
__call__()方法能让类伪装成一个函数，那么类就能够当做装饰器使用。

用类装饰器去装饰一个函数。
"""
import datetime
import time


class timecount:
    def __init__(self, fn):
        self.fn = fn  # add1在这里传入

    def __call__(self, *args, **kwargs):
        before = datetime.datetime.now()
        x = self.fn(*args, **kwargs)  # (x,y)在这里传入
        end = (datetime.datetime.now() - before).total_seconds()
        print('wraps time is {}'.format(end))
        return x


@timecount
def add1(x, y):  # add1(x,y) = timecount(add1)(x,y)
    time.sleep(10)
    return x + y


print(add1(4, 5))
